package com.packenius.library.xspdf;

/**
 * Static methods to use.
 * @author Christian Packenius, 2013.
 */
class XSStatics {
  static double convertToUserUnits(XSUnitType unitType, double size) {
    return convertToUserUnits(size, unitType);
  }

  static double convertToUserUnits(double size, XSUnitType unitType) {
    switch (unitType) {
    case userUnits:
      return size;
    case mm:
      return size * 72.0 / 25.4;
    case inch:
      return size * 72.0;
    }
    return size;
  }

  static byte[] concat(byte[]... bas) {
    int fullLength = 0;
    for (byte[] ba : bas) {
      fullLength += ba.length;
    }
    int i = 0;
    byte[] fullBA = new byte[fullLength];
    for (byte[] ba : bas) {
      int baLength = ba.length;
      System.arraycopy(ba, 0, fullBA, i, baLength);
      i += baLength;
    }
    return fullBA;
  }

  /**
   * Escape characters ( \ ) in standard string.
   * @param s String to escape.
   * @return Destination string.
   */
  public static String escapeStandardStringCharacters(String s) {
    s = s.replace("\\", "\\\\").replace("(", "\\(").replace(")", "\\)");
    return s;
  }
}
